{% extends "templates/main_template.html.j2" %}

{% import "macros/issues_table.html.j2" as ISSUES_TABLE %}



{% block title %}Запросы · Farado{% endblock %}

{% set active_menu = 'issues' %}


{#----------------------------------------------------------------------------#}
{% block styles %}
  {{ ISSUES_TABLE.STYLES() }}
  <link href="/static/css/page-toolbar.css" rel="stylesheet" type="text/css" />
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block breadcrumb %}
  <ol class="breadcrumb">
    <li class="breadcrumb-item active" aria-current="page">Запросы</li>
  </ol>
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block content %}
  <div class="page-toolbar">
    {% if restriction.is_create_enabled %}
      <button
          class="btn btn-outline-primary btn-sm dropdown-toggle"
          type="button"
          id="dropdownMenuAddIssue"
          data-bs-toggle="dropdown"
          aria-expanded="false">Добавить <i class="bi bi-caret-down-fill" class="ml-1"></i></button>
      <ul class="dropdown-menu" aria-labelledby="dropdownMenuAddIssue">
        {% for issue_kind in project_manager.issue_kinds() %}
          {% set workflow = project_manager.workflow(issue_kind.workflow_id) %}
          <li>
            <a  class="dropdown-item"
                href="/issues/add_issue?issue_kind_id={{ issue_kind.id }}">
              {{- workflow.caption|e }}: {{ issue_kind.caption|e -}}
            </a>
          </li>
        {% endfor %}
      </ul>
    {% endif %}
  </div>

  <div class="table-container">
    {{ ISSUES_TABLE.TAG(columns, column_helper) }}
  </div>
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block scripts %}
  {{ ISSUES_TABLE.SCRIPTS() }}

  <script>
    document_ready_function = function() {
      {{ ISSUES_TABLE.DOCUMENT_READY_SCRIPT(columns, column_helper) }}

      {% for field, value in filter_fields.items() -%}
        filter_field('{{ field }}', '{{ value }}');
        {% if not loop.last %}
          issues_table.column('{{ field }}:name').search('{{ value }}');
        {% else %}
          issues_table.column('{{ field }}:name').search('{{ value }}').draw();
        {% endif %}
      {%- endfor %}
    }
  </script>
{% endblock %}
